package org.itboys.mobile.controller.web;

import org.itboys.admin.tools.AdminSessionHolder;
import org.itboys.commons.CommonConstants;
import org.itboys.commons.utils.tools.LongUtil;
import org.itboys.framework.query.JsonPageUtils;
import org.itboys.framework.spring.controller.BaseController;
import org.itboys.mobile.common.SundayCommonConstants;
import org.itboys.mobile.entity.mongo.SundayMember;
import org.itboys.mobile.entity.mysql.product.SundayProduct;
import org.itboys.mobile.service.SundayDesktopService;
import org.itboys.mobile.util.ResponseMessage;
import org.itboys.param.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;

/**
 * 作者：jiangxiong
 * 日期：2017年5月8日
 * 联系方式 ：empty90911@126.com
 * 描述：圣代_后台首页_controller
 */
@Controller
@RequestMapping("/sunday/web/desktop")
public class SundayDesktopController extends BaseController {

    @Autowired
    private SundayDesktopService desktopService;

    /**
     * 质押物  主页
     * @param request
     * @param model
     * @return
     */
    @RequestMapping("/index" )
    public  String index(HttpServletRequest request,
                           Model model){
        //2018年3月14日，判断登陆用户是后台管理员还是商户自己
        if(LongUtil.isNotZreo(AdminSessionHolder.getPlatformMemberId())){
            //返回商户主页
            Map<String,Object> result=desktopService.getDesktopDataByShop(AdminSessionHolder.getPlatformMemberId());
            model.addAttribute("result",result);
            return "/sunday/desktop/index2";
        }else{
            //返回系统主页
            Map<String,Object> result=desktopService.getDesktopData();
            model.addAttribute("result",result);
            return "/sunday/desktop/index";
        }

    }

    /**
     * 获取今日数据前10
     * @param type 1商品销售前10，2门店销售前10，3分销佣金前10
     */
    @RequestMapping("/getToadyTopTen")
    public void getToadyTopTen(HttpServletRequest request,
                       HttpServletResponse response,
                       @RequestParam(value="type",required=true)Integer type
    ) {
        try {
            PageResult result=desktopService.getTodayTopTen(type);
            JsonPageUtils.renderJsonPage(result.getTotal(),result.getData(),response);
        } catch (Exception e) {
            e.printStackTrace();
            ResponseMessage.error(CommonConstants.FAIL_CODE, CommonConstants.FAIL);
        }
    }

}
